<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8" />
		<title>魏远商城</title>
		<link rel="stylesheet" type="text/css" href="../../css/login/forget_p.css" />
	</head>

	<body>
		<div class="wrap">
			<div class="top">
				<div class="top_content imageLogo">
					<img src="../../image/Logo.png" /><span class="welcome">忘记密码</span>
				</div>
				<div class="forget1">
					<div class="f_step">
						<span class="step1"><img class="step1img" src="../../image/step1y.png"><span>手机验证</span></span>
						<span class="step_line1">
						<span><span class="step1_l" style="background-color: #FFC100;"></span><span class="step1_r"></span></span>
						</span>
						<span class="step2"><img class="step2img" src="../../image/step2h.png"><span>密码重置</span></span>
						<span class="step_line2">
						<span><span class="step2_l"></span><span class="step2_r"></span></span>
						</span>
						<span class="step3"><img class="step3img" src="../../image/step3h.png"><span>完成</span></span>
					</div>

					<div class="forfet1_con">
						<div>
							<div class="phone_d fill_d">
								<span>手机号</span>
								<input type="text" maxlength="11" onblur="ph()" class="phonenum" placeholder="请输入手机号码" />
								<span class="tips tips0">*请输入符合规格的手机号</span>
							</div>
							<div class="yan fill_d">
								<span>验证码</span>
								<input type="text" class="yanzhengma" placeholder="请输入手机验证码" />
								<span class="get_yan get_yan1">获取验证码</span>
								<span class="tips05 ">*请输入验证码哦</span>
							</div>
							<div class="re_submits1 re_submit">
								下一步
							</div>
						</div>
					</div>

					<div class="forfet2_con" style="display: none;">
						<div>
							<div class="password_d fill_d">
								<span>设置密码</span>
								<input onblur="ps1()" type="password" class="password1 passWord1" placeholder="请输入6~30位数字的/英文的密码" />
								<span class="tips tips1" style="display: none;">*请输入符合规格的密码</span>
							</div>
							<div class="apassword_d fill_d">
								<span>确认密码</span>
								<input onblur="ps2();ps()" type="password" class="password1 passWord2" placeholder="请确认两次密码相同" />
								<span class="tips tips2" style="display: none;">*请输入符合规格的密码</span>
							</div>
							<div class="re_submits2 re_submit">
								下一步
							</div>
						</div>
					</div>

					<div class="forfet3_con" style="display: none;">
						<div>
							<div class="re_success">
								<div class="re_success_con">
									<div></div>
									<div>
										<p>恭喜！您已修改密码成功！</p>
										<p>正在为您跳转到<span>首页</span>,请稍等...</p>
									</div>
								</div>
							</div>
						</div>
					</div>

				</div>
			</div>
		</div>
		<script src="../../assets/jquery-3.1.1.min.js"></script>
		<script type="text/javascript" src="../../js/url.js"></script>
		<script>
			var hm1 = /^1[34578]\d{9}$/;

			function ph() {
				if(!hm1.test($('.phonenum').val())) {
					$('.tips').css('display', 'inline-block');
				} else {
					$('.tips').css('display', 'none');
				}
			}

			var wait = 60;
			var $code = $(".get_yan1");
			var timer;

			function time() {
				if(wait == 0) {
					clearInterval(timer);
					$code.attr("disabled", false);
					//	$code.value = "获取验证码";
					$code.text("获取验证码");
					wait = 60;
					$('.get_yan1').css('background-color', '#F5F5F5');
				} else { // www.jbxue.com
					$code.attr("disabled", true);
					$code.css('background-color', '#c7c2c2');
					//$code.value = wait + "s后可重发";
					wait--;
					$code.text(wait + "s后可重发");
				}
			}

			var hm = /^1[34578]\d{9}$/;
			$('.get_yan1').on('click', function() {
				if(!hm.test($('.phonenum').val())) {
					$('.tips').css('display', 'inline-block');
				} else {
					codejk();
				}
			})

			function codejk() {
				$.ajax({
					url: ur + '/mobilemember/frontmember/getPhoneVerifyCode',
					type: 'post',
					dataType: 'json',
					data: {
						'memberVO.phone': $('.phonenum').val(),
						'type': 'forget-password',
						'data': ''
					},
					success: function(data) {
						if(data.result.meta.code == 200) {
							console.log(JSON.stringify(data) + '短信')
							var n = data.result.meta.code;
							if(n == '200') {
								timer = setInterval(function() {
									time();
								}, 1000);
							} 
						}else if(n == '204') {
							$('.tips05').css('display', 'block')
							$('.tips05').text('*系统繁忙，请稍后再试');
//							alert($('.tips05').text())
						} else if(n == '500') {
							$('.tips05').css('display', 'block')
							$('.tips05').text('*系统繁忙，请稍后再试');
//							alert($('.tips05').text())
						}else{
							$('.tips05').css('display', 'block')
							$('.tips05').text('*系统繁忙，请稍后再试');
//							alert($('.tips05').text())
						}
					},
					error: function(e) {
						console.log(JSON.stringify(e) + '错误');

					}
				})
			}

			$('.re_submits1').on('click', function() {
				sessionStorage.wyshopzhmimap = $('.phonenum').val();
				sessionStorage.wyshopzhmimay = $('.yanzhengma').val();
				if($('.phonenum').val() == '') {
					$('.tips0').css('display', 'inline-block');
				} else if($('.yanzhengma').val() == '') {
					$('.tips05').css('display', 'inline-block');
				} else {
					co();
				}

				function co() {
					$.ajax({
						url: ur + '/mobilemember/frontmember/checkCode',
						type: 'post',
						dataType: 'json',

						data: {
							'memberVO.phone':$('.phonenum').val(),
							'phoneCode': $('.yanzhengma').val(),
						},
						success: function(data) {
							if(data.msg == '验证成功') {
								$('.forfet1_con').css('display', 'none');
								$('.forfet2_con').css('display', 'block');
								$('.step1img').attr('src', '../../image/step1h.png');
								$('.step2img').attr('src', '../../image/step2y.png');

								$('.step1_l').css('background', '#eeeeee');
								$('.step1_r').css('background', '#ffc100');
								$('.step2_l').css('background', '#ffc100');
								$('.step2_r').css('background', '#eeeeee');
							}
							if(data.msg == '验证失败') {
								$('.tips05').css('display', 'block');
								$('.tips05').css('right', '-180px')
								$('.tips05').text('*验证码错误，请重新输入');
								
							}

						},
						error: function(e) {
							console.log(JSON.stringify(e) + '错误');

						}
					})
				}
			})

			function ps1() {
				if($('.passWord1').val().length < 6) {
					$('.tips1').css('display', 'block');
				} else {
					$('.tips1').css('display', 'none');
				}
			}

			function ps2() {
				if($('.passWord2').val().length < 6) {
					$('.tips2').css('display', 'block');
				} else {
					$('.tips2').css('display', 'none');
				}
			}

			function ps() { //检验两次密码
				if(($('.passWord1').val()) && ($('.passWord2').val()) != '' && ($('.passWord1').val().length >= 6) && ($('.passWord2').val().length >= 6)) {
					if(($('.passWord1').val() != $('.passWord2').val())) {
						$('.tips1').text('*两次密码不一致，请重新输入');
						$('.tips2').text('*两次密码不一致，请重新输入');
						$('.tips1').css('display', 'block');
						$('.tips2').css('display', 'block');
						return;
					} else {
						$('.tips1').css('display', 'none');
						$('.tips2').css('display', 'none');
					}
				}
			}

			$('.re_submits2').on('click', function() {
				if($('.password1').val() == '') {
					$('.tips1').css('display', 'block');
				} else if($('.passWord1').val().length < 6) {
					$('.tips1').css('display', 'block');

				} else if($('.passWord2').val().length < 6) {
					$('.tips2').css('display', 'block');

				} else if($('.password2').val() == '') {
					$('.tips2').text('*密码不能为空');
					$('.tips2').css('display', 'block');
				} else if($('.passWord1').val() != $('.passWord2').val()) {
					$('.tips2').css('display', 'block');
				} else {
					$.ajax({
						type: "post",
						url: ur + "/mobilemember/frontmember/getPassword",
						dataType: 'json',
						data: {
							'memberVO.password': $('.password1').val(),
							'phoneCode': sessionStorage.wyshopzhmimay,
							'memberVO.phone': sessionStorage.wyshopzhmimap
						},
						success: function(data) {
							if(data.result.meta.code == "200") {
								$('.forfet1_con').css('display', 'none');
								$('.forfet2_con').css('display', 'none');
								$('.forfet3_con').css('display', 'block');
								$('.step1img').attr('src', '../../image/step1h.png');
								$('.step2img').attr('src', '../../image/step2h.png');
								$('.step3img').attr('src', '../../image/step3y.png');
								$('.step1_l').css('background', '#eeeeee');
								$('.step1_r').css('background', '#eeeeee');
								$('.step2_l').css('background', '#eeeeee');
								$('.step2_r').css('background', '#ffc100');
								setTimeout(function(){
									sign();
								},3000);
								/*登录*/
								function sign(){
									$.ajax({
										type: 'post',
										url: ur + '/mobilemember/frontmember/dologin',
										dataType: 'json',
										data: {
											"memberVO.loginName": $('.phonenum').val(),
											"memberVO.password": $('.password1').val(),
										},
										success: function(data) {
											var panduan = data.result.meta.code;
											if(panduan == '200') {
												if(data.result.data.isAdmin == 1) {
													localStorage.wyshopisAdmin = data.result.data.isAdmin;
												} else if(data.result.data.isAdmin == 2) {
													localStorage.wyshoppriseId = data.result.data.enterpriseId;
													localStorage.wyshopisAdmin = data.result.data.isAdmin;
												}
												localStorage.wyshoptoken = data.result.data.token;
												window.location.replace("../home/home.html");
											} 
										},
										error: function(e) {
											console.log(e + '登录错误')
										}
									});
								}
							} else if(data.result.meta.code == "204") {
								alert('手机号码有误,请重新填写');
							} else if(data.result.meta.code == "201") {
								alert('验证码不正确');
							} else {
								alert('系统繁忙，请稍后再试');
							}

						},
						error: function(e) {
							console.log(e + '登录失败')
							mui.toast('请检查您的网络...')
						}
					});
				}
			})
		</script>
	</body>

</html>